﻿Imports System.Data.OleDb
Public Class NguyenLieuDAO
    Public Function GetNguyenLieu() As DataTable
        Dim sql As String = "select * from Kho"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub AddNguyenLieu(ByVal newNL As NguyenLieuDTO)
        Dim sql As String = String.Format("insert into Kho(MaNL,TenNL,MaNhomNL,DonVi,SoLuong,KhoiLuong,MaNhaCungCap) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", _
                                           newNL.MaNL, newNL.TenNL, newNL.MaNhom, newNL.DonVi, newNL.SoLuong, newNL.KhoiLuong, newNL.MaNhaCC, newNL.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(Sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Dữ liêu bị sai vui lòng kiểm tra lại !")
        End Try
        cn.Close()
    End Sub

    Public Sub DelNguyenLieu(ByVal delNL As NguyenLieuDTO)
        Dim sql As String = String.Format("delete from Kho where STT={0}", delNL.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdateNguyenLieu(ByVal newNL As NguyenLieuDTO)
        Dim sql As String = String.Format("update Kho set MaNL='{0}',TenNL='{1}',MaNhomNL='{2}',DonVi='{3}',SoLuong='{4}',KhoiLuong='{5}',MaNhaCungCap='{6}' where STT={7}", _
                                          newNL.MaNL, newNL.TenNL, newNL.MaNhom, newNL.DonVi, newNL.SoLuong, newNL.KhoiLuong, newNL.MaNhaCC, newNL.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Vui lòng kiểu tra lại dữ liệu !")
        End Try
        cn.Close()
    End Sub
End Class
